package com.topscore.marketing.promotion.config;

import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EntityScan("com.topscore.marketing.*")
public class AppConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.topscore.marketing.promotion.site"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Top Score Marketing Promotion API")
                .description("Spring Cloud官方帮助文档：http://projects.spring.io/spring-cloud/spring-cloud.html")
                .termsOfServiceUrl("http://blog.didispace.com/")
                .contact(new Contact("邓斌", "http://localhost/ui/sample/hello", "dengbin19910916@163.com"))
                .version("1.0")
                .build();
    }
}
